
from django.core.management.base import BaseCommand
from apps.myauth.models import myUser, Department
from rest_framework.response import Response


class Command(BaseCommand):
    def handle(self, *args, **options):
        management = Department.objects.get(name='教务处')
        one = Department.objects.get(name='210701')
        two = Department.objects.get(name='210702')
        three = Department.objects.get(name='210703')
        four = Department.objects.get(name='210704')
        five = Department.objects.get(name='210705')

        # 教务处的管理人员，都是superuser用户
        # 1. 东东：教务处组长
        dongdong = myUser.objects.create_superuser(email="dongdong@qq.com", realname='东东', password='111111', department=management)
        # 2. 多多：教务处
        duoduo = myUser.objects.create_superuser(email="duoduo@qq.com", realname='多多', password='111111', department=management)
        # 3. 张三：一班老师
        zhangsan = myUser.objects.create_user(email="zhangsan@qq.com", realname='张三', password='111111', department=one,status=1)
        # 4. 李四：二班老师
        lisi = myUser.objects.create_user(email="lisi@qq.com", realname='李四', password='111111',
                                                   department=two,status=1)
        # 5. 王五：三班老师
        wangwu = myUser.objects.create_user(email="wangwu@qq.com", realname='王五', password='111111',
                                               department=three,status=1)
        # 6. 赵六：四班老师
        zhaoliu = myUser.objects.create_user(email="zhaoliu@qq.com", realname='赵六', password='111111',
                                                 department=four,status=1)
        # 7. 孙七：五班老师
        sunqi = myUser.objects.create_user(email="sunqi@qq.com", realname='孙七', password='111111',
                                                  department=five,status=1)
        # 学生
        xiaozhang = myUser.objects.create_user(email="xiaozhang@qq.com", realname='小张', password='111111',
                                           department=one,status=1)
        xiaoming = myUser.objects.create_user(email="xiaoming@qq.com", realname='小明', password='111111',
                                           department=two,status=1)
        xiaoyang = myUser.objects.create_user(email="xiaoyang@qq.com", realname='小杨', password='111111',
                                           department=three,status=1)
        xiaoliang = myUser.objects.create_user(email="xiaoliang@qq.com", realname='小良', password='111111',
                                           department=four,status=1)
        xiaofeng = myUser.objects.create_user(email="xiaofeng@qq.com", realname='小冯', password='111111',
                                           department=five,status=1)


        # 指定teacher和manager

        # 1. 教务处
        management.teacher = dongdong
        management.manager = None

        # 2. 一班
        one.teacher = zhangsan
        one.manager = dongdong

        # 3. 二班
        two.teacher = lisi
        two.manager = dongdong

        # 4. 三班
        three.teacher = wangwu
        three.manager = dongdong

        # 5. 四班
        four.teacher = zhaoliu
        four.manager = duoduo

        # 6. 五班
        five.teacher = sunqi
        five.manager = duoduo

        management.save()
        one.save()
        two.save()
        three.save()
        four.save()
        five.save()

        self.stdout.write('初始用户创建成功！')

